package com.xbts.web.controller.system;

import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.core.page.TableDataInfo;
import com.xbts.common.enums.BusinessType;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.system.domain.CnCommonCloudType;
import com.xbts.system.service.ICnCommonCloudTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 政务云服务器类型Controller
 * @author xbts
 * @date 2023-08-23
 */
@Api("政务云服务器类型")
@RestController
@RequestMapping("/system/common/type")
public class CnCommonCloudTypeController extends BaseController {

    @Autowired
    private ICnCommonCloudTypeService cnCommonCloudTypeService;

    /**
     * 查询政务云服务器类型列表
     */
    @ApiOperation("查询政务云服务器类型列表")
//    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CnCommonCloudType cnCommonCloudType) {
        startPage(cnCommonCloudType);
        List<CnCommonCloudType> list = cnCommonCloudTypeService.selectCnCommonCloudTypeList(cnCommonCloudType);
        return getDataTable(list);
    }

    /**
     * 导出政务云服务器类型列表
     */
    @ApiOperation("导出政务云服务器类型列表")
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "政务云服务器类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody CnCommonCloudType cnCommonCloudType) {
        List<CnCommonCloudType> list = cnCommonCloudTypeService.selectCnCommonCloudTypeList(cnCommonCloudType);
        ExcelUtil<CnCommonCloudType> util = new ExcelUtil<CnCommonCloudType>(CnCommonCloudType.class);
        util.exportExcel(response, list, "政务云服务器类型数据");
    }

    /**
     * 获取政务云服务器类型详细信息
     */
    @ApiOperation("获取政务云服务器类型详细信息")
    @ApiImplicitParam(name = "id", value = "政务云服务器类型ID", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(cnCommonCloudTypeService.selectCnCommonCloudTypeById(id));
    }

    /**
     * 新增政务云服务器类型
     */
    @ApiOperation("新增政务云服务器类型")
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "政务云服务器类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CnCommonCloudType cnCommonCloudType) {
        return toAjax(cnCommonCloudTypeService.insertCnCommonCloudType(cnCommonCloudType));
    }

    /**
     * 修改政务云服务器类型
     */
    @ApiOperation("修改政务云服务器类型")
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "政务云服务器类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CnCommonCloudType cnCommonCloudType) {
        return toAjax(cnCommonCloudTypeService.updateCnCommonCloudType(cnCommonCloudType));
    }

    /**
     * 删除政务云服务器类型
     */
    @ApiOperation("删除政务云服务器类型")
    @ApiImplicitParam(name = "ids", value = "政务云服务器类型ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "政务云服务器类型", businessType = BusinessType.DELETE)
	@PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> ids) {
        return toAjax(cnCommonCloudTypeService.deleteCnCommonCloudTypeByIds(ids));
    }
}
